const path = require('path');
const fs = require('fs');


fs.readFile(path.join(__dirname, '../', 'data.json'), 'utf8', (err, content) => {
  let list = JSON.parse(content);
  if (err) return;
  let arr = [];

  list.forEach((item) => {
    let sql = `insert into book (name,author,category,description) values ('${item.name}','${item.author}','${item.category}','${item.desc}');`;
    arr.push(sql);
  })
  fs.writeFile(path.join(__dirname, 'data.sql'), arr.join(''), (err) => {
    console.log("init data finished!");
  })
  
})